<template>
	<view class="wrap">
		<view class="main" v-if="state">
			<view class="b-head">
				<view class="b-title">{{state.title}}</view>
				<view class="b-info">
					<view class="s-time">{{timeFormat(state.publish_time, 'yyyy-MM-dd')}}</view>
					<view class="s-views">
						<view class="iconfont icon-account"></view>
						<view class="s-cont">{{state.count_view}}</view>
					</view>
				</view>
			</view>
			<view class="b-rich">
				<rich-text :nodes="contentRich"></rich-text>
			</view>
		</view>
		<!-- 加载中 -->
		<load-more :loadingType="loadingType" :loadingText="loadingText"></load-more>
	</view>
</template>

<script>
	import {
		getQuestionDetail
	} from '@/service/api/content.js'
	import {
		formatRichText
	} from '@/common/util.js'
	import mixinsCommon from '@/mixins/common.js'
	export default {
		mixins: [mixinsCommon],
		data() {
			return {
				state: null,
				loadingType: 1,
				loadingText: '',
			}
		},
		computed: {
			contentRich() {
				return formatRichText(this.state.content)
			}
		},
		onLoad(options) {
			getQuestionDetail(options.id).then(([err, res]) => {
				console.log('getQuestionDetail', err, res)
				if (!err) {
					this.loadingType = -1
					this.state = res
					uni.setNavigationBarTitle({
						title: res.title
					})
				} else {
					this.loadingType = 3
					this.loadingText = err.data.msg || '加载失败'
				}
			})
		}
	}
</script>

<style lang="scss">
	page {
		padding-bottom: env(safe-area-inset-bottom);
		background: $pq-bg-color;
	}

	.wrap {
		background: #fff;
	}

	.main {
		padding: 20upx;
	}

	.b-head {
		margin-top: 20upx;

		.b-title {
			font-size: 30upx;
			color: #333;
		}

		.b-info {
			margin-top: 20upx;
			display: flex;
			justify-content: space-between;

			.s-time {
				font-size: 26upx;
				color: #999;
			}

			.s-views {
				display: flex;
				align-items: center;

				.iconfont {
					margin-right: 10upx;
					font-size: 30upx;
					color: #eee;
				}

				.s-cont {
					font-size: 26upx;
					color: #999;
				}
			}
		}
	}

	.b-rich {
		margin-top: 50upx;
		background: #fff;
		font-size: 28upx;
		min-height: 500upx;
	}
</style>
